//
//  MyStoryboardSegue.m
//  SegueDemo
//
//  Created by Guo Feng on 13-3-11.
//  Copyright (c) 2013年 CUIT. All rights reserved.
//

#import "MyStoryboardSegue.h"
#import <QuartzCore/QuartzCore.h>

@implementation MyStoryboardSegue

- (void)perform {
        
    UIViewController *sourceViewController = self.sourceViewController;
    UIViewController *destionationViewController = self.destinationViewController;
    
    
    UIGraphicsBeginImageContext(destionationViewController.view.bounds.size);
    [destionationViewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *destionationViewControllerImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    
    UIImageView *destionationViewControllerImageView = [[UIImageView alloc] initWithImage:destionationViewControllerImage];
    [sourceViewController.parentViewController.view addSubview:destionationViewControllerImageView];
    
    
    CGAffineTransform scaleTransform = CGAffineTransformMakeScale(0.1, 0.1);
    CGAffineTransform rotateTransform = CGAffineTransformMakeRotation(M_PI);
    destionationViewControllerImageView.transform = CGAffineTransformConcat(scaleTransform, rotateTransform);
    
    
    CGPoint latterCenter = destionationViewControllerImageView.center;
    CGPoint formerCenter = CGPointMake(latterCenter.x - destionationViewControllerImageView.bounds.size.width, latterCenter.y);
    destionationViewControllerImageView.center = formerCenter;
    
    
    [UIView animateWithDuration:0.5 animations:^(void){
        destionationViewControllerImageView.transform = CGAffineTransformIdentity;
        destionationViewControllerImageView.center = latterCenter;
    }completion:^(BOOL finished) {
        [destionationViewControllerImageView removeFromSuperview];
        
        [sourceViewController presentViewController:destionationViewController animated:NO completion:nil];
    }];
}
@end


























